<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>云创云盘 - 登录</title>
    <meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
    <meta name="description"
          content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="css/bootstrap.min.css?v=3.3.7" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">

    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html"/>
    <![endif]-->
    <script>if (window.top !== window.self) {
        window.top.location = window.location;
    }</script>
    <script src="js/axios.min.js"></script>
    <script src="https://unpkg.com/vue@2/dist/vue.js"></script>
<!--    <script src="js/vue.js"></script>-->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
</head>

<body class="gray-bg">

<div id="app" class="middle-box text-center loginscreen  animated fadeInDown">
    <div>
        <div>

            <h1 class="logo-name">云</h1>

        </div>
        <h3>欢迎使用 云创云盘</h3>

        <form class="m-t" role="form" v-on:submit.prevent>
            <div class="form-group">
                <input type="text" class="form-control" v-model="userName" placeholder="用户名"
                       required="请输入用户名" @submit="getUserMessage()">
            </div>
            <div class="form-group">
                <input type="password" class="form-control" v-model="password" placeholder="密码" required="请输入密码">
            </div>
            <div class="form-group">
                <div class="input-group">
                    <input type="text" class="form-control" v-model="verCode" placeholder="验证码">
                    <span class="input-group-addon no-padding"><img
                            src="/captcha" height="32"></span>
                </div>
            </div>
            <button @click="onSubmit" class="btn btn-primary block full-width m-b">登 录</button>

            <a href="register.html">注册一个新账号</a>
            </p>

        </form>
    </div>
</div>

<!-- 全局js -->
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.7"></script>

<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
<!--统计代码，可删除-->

<script>
    new Vue({
        el: '#app',
        data() {
            return {
                userName: 'jiangegege',
                password: '123456',
                verCode: "",
            }
        },
        methods: {
            getUserMessage() {
                localStorage.setItem('username', this.formList.userName);
            },
            // 提交数据
            onSubmit() {
                let formList = {
                    userName: this.userName,
                    password: this.password,
                    verCode: this.verCode,
                }
                var that = this;
                axios.post("http://localhost:8080/user/login", formList)
                    .then(response => {
                        console.log(response.data);
                        var code = response.data.code;
                        var message = response.data.message;
                        var userAccount;
                        if (response.data.data !== null) {
                            userAccount = response.data.data.userAccount;
                        }
                        // console.log(response.data);
                        // console.log(code);
                        // console.log(message);
                        // console.log(username);
                        if (code === 2000) {
                            that.$message({
                                message: '欢迎您, ' + userAccount + ' 大人！',
                                type: 'success',
                            });
                            setTimeout(function(){
                                window.location.href = "/clients.html";
                            }, 1000);
                        } else {
                            that.$message({
                                message: message,
                                type: 'error',
                            });
                            setTimeout(function(){
                                window.location.href = "/login.html";
                            }, 1200);
                        }
                    })
            }
        },
        created() {
            var saveUsername = localStorage.getItem('username')
            this.formList.userName = saveUsername
        }
    })
</script>

</body>

</html>
